package com.agentfactory.teleoreactive.core;

import com.agentfactory.logic.update.lang.Predicate;
import com.agentfactory.platform.core.AgentID;
import com.agentfactory.platform.impl.StringMessage;
import com.agentfactory.teleoreactive.interpreter.Utilities;
import com.agentfactory.teleoreactive.interpreter.mentalstate.Action;

public class SendAction extends Action {

	@Override
	public boolean execute(Predicate activity) {
		String performative = Utilities.presenter.toString(activity.termAt(0));
		AgentID receiver = Utilities.toAgentID(activity.termAt(1));
		String content = Utilities.presenter.toString(activity.termAt(2));

        StringMessage message = StringMessage.newInstance();
        message.setPerformative(performative.toUpperCase());
        message.setSender(agent.getAgentID());
        message.getReceivers().add(receiver);
        message.setContent(content.toString());
        message.setLanguage("AFAPL");
        message.setOntology("none");
        message.setProtocol("none");
        
        return agent.send(message);
	}

}
